#region Import Declarations

using System.IO;
using System.Text;
using System.Xml;
using CommunityServer.Configuration;
using CommunityServer.Components;

#endregion

namespace CommunityServerStuff.Writers
{

    /// <summary>
    /// 
    /// </summary>
    class OpenSearchWriter : WriterBase
    {

        #region Private Members

        private CSContext _csContext;
        private SiteSettings _siteSettings;

        #endregion

        #region Methods

        #region Default Constructor

        /// <summary>
        /// 
        /// </summary>
        /// <param name="siteSettings"></param>
        /// <param name="sw"></param>
        internal OpenSearchWriter(SiteSettings siteSettings, StringWriter sw)
            : base(siteSettings, sw)
        {
            _csContext = CSContext.Current;
            _siteSettings = _csContext.SiteSettings;
        }

        #endregion

        #region Build

        /// <summary>
        /// 
        /// </summary>
        public override void Build()
        {
            this.Formatting = Formatting.Indented;
            this.WriteStartDocument();
            this.WriteStartElement("OpenSearchDocument");
            this.WriteAttributeString("xmlns", "http://a9.com/-/spec/opensearch/1.1/");
            this.WriteElementString("ShortName", _siteSettings.SiteName);
            this.WriteElementString("Description", _siteSettings.SiteDescription);
            this.WriteElementString("Contact", _siteSettings.AdminEmailAddress);
            this.WriteStartElement("Url");
            this.WriteAttributeString("type", "text/html");
            this.WriteAttributeString("template", _siteSettings.SiteUrl + "/search/SearchResults.aspx?q={searchTerms}");
            this.WriteEndElement();
            this.WriteEndElement();
            this.WriteEndDocument();
        }

        #endregion

        #endregion

    }

}